"""
URL configuration for mysite project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from main import views
from rest_framework.routers import DefaultRouter
from rest_framework_simplejwt.views import (
    TokenObtainPairView,
    TokenRefreshView,
    TokenVerifyView
)

# 创建一个路由实例  用来生成列表路由 和详情路由
router = DefaultRouter()
# 通过注册一个资源 来注册资源对应的api
# 生成路由
# /categorys/     name=category-list
# /categorys/<int:pk>  name=category-detail

router.register("categorys", views.CategoryViewSet)
router.register("books", views.BookViewSet)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api-auth/', include('rest_framework.urls')),
    path('', include(router.urls)),

    # path('categorys/', views.category_list, name='category-list'),
    # path('categorys/<int:pk>/', views.category_detail, name='category-detail'),

    # path('categorys/', views.CategoryListAPIView.as_view(), name='category-list'),
    # path('categorys/<int:pk>/', views.CategoryDetailAPIView.as_view(), name='category-detail'),

    # path('categorys/', views.CategoryListGenericAPIView.as_view(), name='category-list'),
    # path('categorys/<int:pk>/', views.CategoryDetailGenericAPIView.as_view(), name='category-detail'),

    # path('categorys/', views.CategoryListGenericMixinAPIView.as_view(), name='category-list'),
    # path('categorys/<int:pk>/', views.CategoryDetailGenericMixinAPIView.as_view(), name='category-detail'),

    # path('categorys/', views.CategoryViewSetMixinGenericAPIView.as_view({'get': 'list', 'post': 'create'}), name='category-list'),
    # path('categorys/<int:pk>/', views.CategoryViewSetMixinGenericAPIView.as_view({'get': 'retrieve', 'put': 'update', 'delete': 'destroy'}), name='category-detail'),

    # 通过用户名密码获取用户token令牌信息和refresh信息
    path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
    # 拿着refresh刷新信息从新获取token令牌
    path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
    # token校验
    path('api/token/verify/', TokenVerifyView.as_view(), name='token_verify'),
]
